package teacher.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import teacher.bean.Teacher;
import teacher.service.teacher;

import com.opensymphony.xwork2.ActionSupport;

public class mendPas extends ActionSupport{
	
	private Teacher teacher1;
	private Teacher tea2;
	
	private String passOld;
	private String passNew1;
	private String passNew2;
	
	String suc;
	

	public String getSuc() {
		return suc;
	}

	public void setSuc(String suc) {
		this.suc = suc;
	}

	public String getPassOld() {
		return passOld;
	}

	public void setPassOld(String passOld) {
		this.passOld = passOld;
	}

	public String getPassNew1() {
		return passNew1;
	}

	public void setPassNew1(String passNew1) {
		this.passNew1 = passNew1;
	}

	public String getPassNew2() {
		return passNew2;
	}

	public void setPassNew2(String passNew2) {
		this.passNew2 = passNew2;
	}

	public String execute()
	{
		HttpServletRequest request=ServletActionContext.getRequest();
		Teacher tea1=(Teacher)request.getSession().getAttribute("teacher");
		tea2=new teacher().SelectTeacher(tea1);
		
		if(passNew1.equalsIgnoreCase(passNew2)){
			
			System.out.println("1");
		}
		
	if(tea2.getPassword().toString().equalsIgnoreCase(passOld)){
			
			System.out.println("2");
		}
	
	if(new teacher().updateTeacherPas(tea2, passNew1)){
		
		System.out.println("3");
	}
		
		if(passNew1.equalsIgnoreCase(passNew2)&&tea2.getPassword().equalsIgnoreCase(passOld)&&new teacher().updateTeacherPas(tea2, passNew1))
		{
		this.setSuc("success");	
		return SUCCESS;
		}else{
			return ERROR;
		}
	}

}
